package com.lzj.demo.design.controller;

import com.lzj.demo.design.common.ServerResult;
import com.lzj.demo.design.strategy.FileResolveFactory;
import com.lzj.demo.design.strategy.FileTypeResolveEnum;
import com.lzj.demo.design.strategy.fzw.CouponEnum;
import com.lzj.demo.design.strategy.fzw.CouponFactory;
import com.lzj.demo.design.vo.CouponVO;
import com.lzj.demo.design.vo.FileVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/demo/design")
@Slf4j
public class StrategyController {
    @Resource
    FileResolveFactory fileResolveFactory;
    @Resource
    CouponFactory couponFactory;

    @PostMapping("/strategy")
    public ServerResult strategy(@RequestBody FileVO fileVO){
        return fileResolveFactory.resolveFile(FileTypeResolveEnum.getEnumByEnCode(fileVO.getFileType()),fileVO.getFileResolveMethod());
    }

    @PostMapping("/strategy2")
    public ServerResult strategy(@RequestBody CouponVO couponVO){
        return ServerResult.success(couponFactory.useCoupon(CouponEnum.getEnumByCode(couponVO.getCouponCode()),couponVO.getSkuPrice()));
    }
}
